//
//  BCSvipPayPassController.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/20.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCSvipPayPassController.h"

//request
#import "BCUserBuySvipRequest.h"

@interface BCSvipPayPassController ()

@property (nonatomic, copy) BCSvipPayPassControllerComplete completeBlock;

@end

@implementation BCSvipPayPassController

+ (void)showPayFromController:(UIViewController *)fromController complete:(BCSvipPayPassControllerComplete)complete {
    BControllerWindow *window = [[BControllerWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //
    BCSvipPayPassController *vc = [BCSvipPayPassController new];
    vc.fromController = fromController;
    vc.showWindow = window;
    vc.completeBlock = complete;
    BCWindowNavigationController *navi = [[BCWindowNavigationController alloc] initWithRootViewController:vc];
    navi.navigationBar.hidden = true;
    navi.navigationBar.barStyle = [vc barStyleFromController:fromController];
    window.rootViewController = navi;
    //
    [window makeKeyAndVisible];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}


- (void)passwordInputFinishAction {
    [self requestUserBuyProjectAction];
}

- (void)requestUserBuyProjectAction {
    [self startLoading];
    BCUserBuySvipRequest *request = [BCUserBuySvipRequest new];
    request.pay_pass = self.passwordTF.text;
    WEAK_SELF
    [request didRequestCompleted:^{
        [wself stopLoading];
    }];
    [request didRequestSuccessed:^(id result, id page) {
        BCUserBuySvipResponse *resp = result;
        [wself handleSuccess:resp];
    }];
    [request didRequestFailed:^(NSError *error) {
        wself.passwordTF.text = nil;
        if (error&&wself.showWindow) {
            NSString *errMsg = error.domain;
            [QMUITips showError:errMsg inView:wself.showWindow hideAfterDelay:[QMUITips smartDelaySecondsForTipsText:errMsg]];
        }
    }];
    [request requestServer];
}
- (void)handleSuccess:(BCUserBuySvipResponse *)resp {
    if (self.completeBlock) {
        self.completeBlock(resp.msg);
    }
    [self backButtonDidClickedAction];
}


@end
